﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using AssetManageSystem.Model.AssetManage;
using AssetManageSystem.Model.OrgManage;


namespace AssetManageSystem.ViewModel.AssetManage.AssetRepairVMs
{
    public partial class AssetRepairListVM : BasePagedListVM<AssetRepair_View, AssetRepairSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
            if (SearcherMode == ListVMSearchModeEnum.MasterDetail)
            {
                return new List<GridAction>
                {
                    this.MakeStandardAction("AssetRepair", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "AssetManage", dialogWidth: 800),
                };
            }
            else
            {
                return new List<GridAction>
                {
                    this.MakeStandardAction("AssetRepair", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-green"),
                    this.MakeStandardAction("AssetRepair", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-blue"),
                    this.MakeStandardAction("AssetRepair", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-red"),
                    this.MakeStandardAction("AssetRepair", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "AssetManage", dialogWidth: 800).SetButtonClass("btn-col-8"),
                    // this.MakeStandardAction("AssetRepair", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-orange"),
                    this.MakeStandardAction("AssetRepair", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-red"),
                    // this.MakeStandardAction("AssetRepair", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "AssetManage", dialogWidth: 800).SetButtonClass("btn-col-4"),
                    this.MakeStandardAction("AssetRepair", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], "AssetManage").SetButtonClass("btn-col-4"),
                };
            }
        }


        protected override IEnumerable<IGridColumn<AssetRepair_View>> InitGridHeader()
        {
            if (SearcherMode == ListVMSearchModeEnum.MasterDetail)
            {
                return new List<GridColumn<AssetRepair_View>>{
                this.MakeGridHeader(x => x.DocNumber),
                this.MakeGridHeader(x => x.UserName_view),
                this.MakeGridHeader(x => x.DepName_view),
                this.MakeGridHeader(x => x.OutDate),
                this.MakeGridHeaderAction(width: 100)
            };
            }
            else
            {
                return new List<GridColumn<AssetRepair_View>>{
                this.MakeGridHeader(x => x.DocNumber),
                this.MakeGridHeader(x => x.UserName_view),
                this.MakeGridHeader(x => x.DepName_view),
                this.MakeGridHeader(x => x.OutDate),
                this.MakeGridHeader(x => x.RepairInfo),
                this.MakeGridHeaderAction(width: 200)
            };
            }
        }

        public override IOrderedQueryable<AssetRepair_View> GetSearchQuery()
        {
            var query = DC.Set<AssetRepair>()
                .CheckEqual(Searcher.RepairAssetId, x => x.RepairAssetId)
                .CheckEqual(Searcher.RepairmanId, x => x.RepairmanId)
                .CheckEqual(Searcher.RepairDepId, x => x.RepairDepId)
                .CheckBetween(Searcher.OutDate?.GetStartTime(), Searcher.OutDate?.GetEndTime(), x => x.OutDate, includeMax: false)
                .CheckContain(Searcher.RepairUnit, x => x.RepairUnit)
                .Select(x => new AssetRepair_View
                {
                    ID = x.ID,
                    DocNumber = x.DocNumber,
                    UserName_view = x.Repairman.UserName,
                    DepName_view = x.RepairDep.DepName,
                    OutDate = x.OutDate,
                    RepairInfo = x.RepairInfo,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class AssetRepair_View : AssetRepair
    {
        [Display(Name = "报修人")]
        public String UserName_view { get; set; }
        [Display(Name = "报修部门")]
        public String DepName_view { get; set; }

    }
}
